define(['jquery', 'FontStyleController', 'renderPage', 'menu'], function ($, FontStyleController, renderPage, menu) {

    function main() {
        var $article = $('.swiper-container');
        var fontStyleController = new FontStyleController();
        var fontStyle = ['small', 'normal', 'big'];

        $.ajax({
            url: './data/0',
            type: 'get',
            dataType: 'text',
            success: function (data) {
                fontStyleController.set(fontStyle[1]);
                var pagesArray = renderPage({
                    article: data,
                    pageClass: "article_page",
                    fontStyleStatus: fontStyleController.getStatus()
                });


                //$article.html(htmlStr);

                var list = [];

                pagesArray.forEach(function (t) {
                    list.push({
                        content: t
                    })
                });

                var swiper = new Swiper({
                    container: document.querySelector('.swiper-container'),
                    data: list,
                    isVertical: false,
                    isLoop: false,
                    keepDefaultClass: [],
                    transition: {
                        name: 'slide',
                        duration: 800,
                        direction: undefined
                    }
                });

                //页面开始滑动
                swiper.on("swipeMoving", function () {
                    menu.unbindEvnet()
                });
                //页面滑动结束
                swiper.on("swipeChanged", function () {
                    menu.bindEvent();
                });
                //在回弹完成时触发
                swiper.on("swipeRestored", function () {
                    menu.bindEvent();
                })

                $article.css(fontStyleController.getStatus().style);
            }
        });
    }

    function loadCss(url) {
        var link = document.createElement("link");
        link.type = "text/css";
        link.rel = "stylesheet";
        link.href = url;
        document.getElementsByTagName("head")[0].appendChild(link);
    }

    return {
        main: main,
        loadCss: loadCss
    }
});